var Random = require('mockjs').Random;
var http = require('http');

let userList = [];
for (let index = 0; index < 20; index++) {
    userList.push({
        id: index + 1,
        name: Random.name()
    })
}

var data = {
    message: "获取用户成功",
    list: userList
}

http.createServer((req, res) => {
    if (req.url == "/user/list") {
        res.setHeader("Access-Control-Allow-Origin", "*");
        res.setHeader("Access-Control-Headers", "content-type");
        res.setHeader("Access-Control-Allow-Methods", "GET,POST");
        res.writeHead(200,{"Content-Type":"application/json"});
        res.end(JSON.stringify(data));
    }
}).listen(8000);